﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QD.SQLHelper
{
    /// <summary>
    /// 通过sql访问MSSQL数据库
    /// </summary>
    public class MSDbContext
    {
        private string connStr;
        public MSDbContext(string connStr)
        {
            this.connStr = connStr;
        }

        /// <summary>
        /// 验证数据库是否连接成功
        /// </summary>
        /// <returns></returns>
        public bool IsConnection(ref string msg)
        {
            using (SqlConnection conn = new SqlConnection(connStr))
            {
                try
                {
                    conn.Open();
                    conn.Close();
                    return true;
                }
                catch (SqlException ex)
                {
                    msg = ex.Message;
                    return false;
                }
            }
        }
    }
}
